package com.memoryangelapplication.sound;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;

import android.os.Handler;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;

public class PlayTextToSpeech implements TextToSpeech.OnInitListener {

	int eventSoundGap = 1;
	TextToSpeech talker;
	String evtTime;
	Activity activity;
	Context context;

	public PlayTextToSpeech(Context context, Activity activity, String passTime) {
		this.evtTime = passTime;
		this.activity = activity;
		this.context = context;
	}
	
	public void playVoice(){

		activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);

		talker = new TextToSpeech(context, this);

		Handler handler = new Handler();
		final Runnable r = new Runnable() {
			public void run() {
				String text = evtTime;
				//talker.speak(text, TextToSpeech.QUEUE_FLUSH, null);
				//talker.speak(text, TextToSpeech.QUEUE_ADD, null);
				talker.speak(text, TextToSpeech.QUEUE_ADD, null);
				//talker.speak(text, TextToSpeech.QUEUE_ADD, null);

			}
		};

		handler.postDelayed(r, eventSoundGap * 1000);

	}

	@Override
	public void onInit(int arg0) {
		// TODO Auto-generated method stub

	}

}
